<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 业绩管理
                </el-breadcrumb-item>
            </el-breadcrumb>

        </div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="query.mobile"  placeholder="手机号"  class="handle-input mr10"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                <el-button type="success"  style="float: right" icon="el-icon-upload2" @click="uploadVisible = true">上传业绩</el-button>

            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
            >
                <el-table-column prop="id" label="Id" width="55" align="center"></el-table-column>
                <el-table-column prop="mobile" label="手机号"></el-table-column>
                <el-table-column prop="hide_mobile" label="隐藏手机号"></el-table-column>
                <el-table-column prop="nickname" label="昵称"></el-table-column>
                <el-table-column prop="achievement" label="业绩"></el-table-column>
                <el-table-column prop="calc_date" label="日期"></el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="prev, next, pager"
                    :current-page="query.page"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>

            <el-dialog
                    title="上传代理业绩"
                    stlye="width:35%"
                    :visible.sync="uploadVisible">
                <el-upload
                        class="upload-demo"
                        ref="upload"
                        action="/admin/xls_upload"
                        :limit="1"
                        :headers="header"
                        :file-list="fileList"
                        :on-success="handleSuccess"
                        :auto-upload="false">
                    <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                    <el-button style="display: block;margin: 10px 0 0 125px"  size="small" type="success" @click="submitUpload">上传到服务器</el-button>
                </el-upload>
            </el-dialog>
        </div>
    </div>
</template>

<script>

export default {
    name: 'order',
    data() {
        return {
            query: {
                page: 1,
                pageSize: 10,
            },
            tableData: [],
            fileList: [],
            pageTotal: 0,
            uploadVisible: false
        };
    },
    created() {
        this.getData();
    },
    methods: {
        submitUpload() {
            this.$refs.upload.submit();
        },
        handleSuccess(res, file){
            this.$message.success("上传成功" + res.data + "条记录");
            this.fileList = []
            this.uploadVisible = false
        },
        getData() {
            this.http.profit(this.query).then(res => {
                if(res.code ===  0) {
                    this.tableData = res.data.data;
                    this.pageTotal = res.data.total;
                } else {
                    this.$message.error(res.msg);
                }
            });
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'page', 1);
            this.getData();
        },


        // 编辑操作
        confirmOk(index, row) {
            this.http.doWithdraw({id: row.id}).then(res => {
                this.getData();
            });
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'page', val);
            this.getData();
        }
    },
    computed: {
        header () {
            return {token: localStorage.getItem('user_token')}
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.el-upload--text{
    height: 100px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
